#include "filename.h"
#include "ui_filename.h"
#include <QIntValidator>
#include <QFileInfo>
#include <QDir>
filename::filename(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::filename)
{
    ui->setupUi(this);
    this->setWindowTitle("请输入视频开始时间");
    QIntValidator *validator1 = new QIntValidator(this);
    ui->lineEdit->setValidator(validator1);
    QIntValidator *validator2 = new QIntValidator(this);
    ui->lineEdit_2->setValidator(validator2);
    QIntValidator *validator3 = new QIntValidator(this);
    ui->lineEdit_3->setValidator(validator3);
    QIntValidator *validator4 = new QIntValidator(this);
    ui->lineEdit_4->setValidator(validator4);
    QIntValidator *validator5 = new QIntValidator(this);
    ui->lineEdit_5->setValidator(validator5);
    QIntValidator *validator6 = new QIntValidator(this);
    ui->lineEdit_6->setValidator(validator6);

    ui->lineEdit->setStyleSheet(
        "QLineEdit {"
        "   background-color: #f0f0f0;"   // 背景色
        "   border: 2px solid #4a90e2;"    // 边框
        "   border-radius: 5px;"           // 圆角
        "   padding: 5px;"                 // 内边距
        "   font-family: Arial;"           // 字体
        "   font-size: 14px;"              // 字号
        "}"
        );

    ui->lineEdit_2->setStyleSheet(
        "QLineEdit {"
        "   background-color: #f0f0f0;"   // 背景色
        "   border: 2px solid #4a90e2;"    // 边框
        "   border-radius: 5px;"           // 圆角
        "   padding: 5px;"                 // 内边距
        "   font-family: Arial;"           // 字体
        "   font-size: 14px;"              // 字号
        "}"
        );
    ui->lineEdit_3->setStyleSheet(
        "QLineEdit {"
        "   background-color: #f0f0f0;"   // 背景色
        "   border: 2px solid #4a90e2;"    // 边框
        "   border-radius: 5px;"           // 圆角
        "   padding: 5px;"                 // 内边距
        "   font-family: Arial;"           // 字体
        "   font-size: 14px;"              // 字号
        "}"
        );
    ui->lineEdit_4->setStyleSheet(
        "QLineEdit {"
        "   background-color: #f0f0f0;"   // 背景色
        "   border: 2px solid #4a90e2;"    // 边框
        "   border-radius: 5px;"           // 圆角
        "   padding: 5px;"                 // 内边距
        "   font-family: Arial;"           // 字体
        "   font-size: 14px;"              // 字号
        "}"
        );
    ui->lineEdit_5->setStyleSheet(
        "QLineEdit {"
        "   background-color: #f0f0f0;"   // 背景色
        "   border: 2px solid #4a90e2;"    // 边框
        "   border-radius: 5px;"           // 圆角
        "   padding: 5px;"                 // 内边距
        "   font-family: Arial;"           // 字体
        "   font-size: 14px;"              // 字号
        "}"
        );
    ui->lineEdit_6->setStyleSheet(
        "QLineEdit {"
        "   background-color: #f0f0f0;"   // 背景色
        "   border: 2px solid #4a90e2;"    // 边框
        "   border-radius: 5px;"           // 圆角
        "   padding: 5px;"                 // 内边距
        "   font-family: Arial;"           // 字体
        "   font-size: 14px;"              // 字号
        "}"
        );

    ui->lineEdit->setPlaceholderText("请输入年");
    ui->lineEdit_2->setPlaceholderText("请输入月");
    ui->lineEdit_3->setPlaceholderText("请输入日");
    ui->lineEdit_4->setPlaceholderText("请输入时");
    ui->lineEdit_5->setPlaceholderText("请输入分");
    ui->lineEdit_6->setPlaceholderText("请输入秒");

    // // 设置占位符样式（通过样式表）
    // ui->lineEdit_2->setStyleSheet(
    //     "QLineEdit::placeholder {"
    //     "   color: #999999;"       // 占位符文字颜色
    //     "   font-style: italic;"   // 斜体样式
    //     "   font-size: 12px;"      // 字号
    //     "}"
    //     );

}

filename::~filename()
{
    delete ui;
}

void filename::setf(QString str)
{
    this->str = str;
}

void filename::on_pushButton_clicked()
{
    if(ui->lineEdit->text().isEmpty())
        return;
    if(ui->lineEdit_2->text().isEmpty())
        return;
    if(ui->lineEdit_3->text().isEmpty())
        return;
    if(ui->lineEdit_4->text().isEmpty())
        return;
    if(ui->lineEdit_5->text().isEmpty())
        return;
    if(ui->lineEdit_6->text().isEmpty())
        return;
    QString name=ui->lineEdit->text()+"_"+
                ui->lineEdit_2->text()+"_"+
                ui->lineEdit_3->text()+"_"+
                ui->lineEdit_4->text()+"_"+
                ui->lineEdit_5->text()+"_"+
                   ui->lineEdit_6->text()+".mp4";

    QFileInfo fileInfo(str);
    QString path=QDir(fileInfo.path()).filePath(name);
    emit fileName(str,path);
    ui->lineEdit->text().clear();
    ui->lineEdit_2->text().clear();
    ui->lineEdit_3->text().clear();
    ui->lineEdit_4->text().clear();
    ui->lineEdit_5->text().clear();
    ui->lineEdit_6->text().clear();
    this->hide();
}

